package cn.ac.siom.query.dao.impl;


import cn.ac.siom.query.dao.CountDAO;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;


@Repository
public class CountDAOImpl extends SqlSessionDaoSupport implements CountDAO {
    @Autowired
    public CountDAOImpl(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }


    @Override
    public Integer sourceCount(Integer type) throws SQLException {
        Map<String, Integer> map = new HashMap<>();
        map.put("type", type);
        if (type == 1 || type == 2 || type == 4 || type == 5) {
            return super.getSqlSession().selectOne("SourceCount.tab_thesis", map);
        } else if (type == 3) {
            return super.getSqlSession().selectOne("SourceCount.item_info", map);
        } else if (type == 6) {
            return super.getSqlSession().selectOne("SourceCount.p_basic", map);
        } else if (type == 7) {
            return super.getSqlSession().selectOne("SourceCount.Patents_info", map);
        } else if (type == 8) {
            return super.getSqlSession().selectOne("SourceCount.Tab_xwlw", map);
        } else {
            return super.getSqlSession().selectOne("SourceCount.Tab_media");
        }
    }

}
